<?php
declare (strict_types=1);
/*
 * 订单
 * 冯子恒
 * 0813
 * */

namespace app\admin\controller\order;

use app\common\service\OrderService;
use think\facade\View;
use think\Request;

class Order
{
    /**
     * 分页参数
     * @var mixed
     */
    protected $pagesize;
    /**
     * 初始化参数
     * Order constructor.
     */
    public function __construct()
    {
        $this->pagesize = config('page.pagesize');
    }

    /**
     * 显示订单列表
     * @return string|\think\Response
     */
    public function index()
    {
        return View::fetch();
    }

    /**
     *初次加载页面展示订单列表
     * Author:William
     * @return \think\response\Json
     */
    public function getOrderList()
    {
        $orderDate = OrderService::getOrderList();
        $data = [
            'code' => 0,
            'msg' => '成功',
            'data' => $orderDate,
        ];
        return json($data);
    }

    /**
     * 按照订单类型和订单状态展示列表数据
     * Author:William
     */
    public function orderType(Request $request)
    {
        $type = $request->get('type');
        $value = $request->get('value');
        $data = OrderService::orderStatusType($type, $value);
        return json($data);
    }

    /**
     * 删除指定资源
     * @param int $id
     * @return \think\Response
     */
    public function delete($id)
    {
        if (!empty($id)) {
            $res = \app\admin\model\order\Order::del($id);
            if ($res != false) {
                return json(['msg' => '删除成功', 'code' => 200, 'data' => '']);
            } else {
                return json(['msg' => '无法删除', 'code' => 1, 'data' => '']);
            }
        }
        return json(['msg' => '参数不正确', 'code' => 1, 'data' => '']);
    }
}
